package compiler;
import java.io.IOException;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;

import javax.mail.internet.AddressException;
import javax.swing.JOptionPane;

import mail_operations.WorkbookMailer;

import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Row;

import data.EmailReminder;
import data.ExceptionInfo;
import data.PortList;

import sheetOperations.WorkbookCreator;
import sheetOperations.WorkbookSegregation;

public class ContractTypeCheckingReport {	
	public static void run(HSSFWorkbook inputWB, boolean email, boolean reminder) throws IOException, ParseException, AddressException{
		//List of marked rows retrieved 
		ExceptionInfo.initialize();
		EmailReminder.initialize();
		
		String rptName = "Contract Checking Report";

		HashMap<String,ArrayList<Row>> wbMap = WorkbookSegregation.segregateWB(inputWB, rptName, reminder);
		ArrayList<String> wbList = WorkbookCreator.createWB(wbMap, reminder);
		//Segregate books separately by origin and destination offices
		for(int i=0;i<wbList.size();i++){
			System.out.println(wbList.get(i));
		}
		if(email){
			WorkbookMailer.sendMailByOrigin(wbList, rptName);
			EmailReminder.writeToFile();
		}
		if(wbList.size()==0){
			JOptionPane.showMessageDialog(null,"No Error file for today!! CHEERS @_@");
		}
		wbMap = null;
		inputWB = null;
		//Check for success or failure
	}
}